package com.jq.ui.enforcement_bill;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.jq.R;
import com.jq.printer.JQPrinter;
import com.jq.printer.Printer_define.ALIGN;
import com.jq.printer.Printer_define.PRINTER_MODEL;
import com.jq.printer.esc.ESC;
import com.jq.printer.esc.ESC.BAR_UNIT;
import com.jq.ui.DemoApplication;

import java.text.SimpleDateFormat;

public class ebMainActivity extends Activity {
    private JQPrinter printer = null;
    private Button buttonPrint = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_enforcement_bill);
		
		buttonPrint = (Button)findViewById(R.id.ButtonEnforementBillPrint);
		
		DemoApplication app = (DemoApplication)getApplication();
		if (app.printer != null)
		{
			printer = app.printer;
		}
		else
		{
			Log.e("JQ", "app.printer null");
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		
		return true;
	}
	
	//byte 1个字节范围是-1~127
	//char 2个字节范围是0~65535
	private char[] logo_data = {0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
			0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 0x07, 0x07, 0x07, 0x07,
			0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03, 0x03, 0x03, 0x03,
			0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x01, 0x03, 0x03, 0x07, 0x0F, 0x0F, 0x1F, 0x1E, 0x3F, 0x3D, 0x7C,
			0x7F, 0xFF, 0xF0, 0xF8, 0xFC, 0xFE, 0xEE, 0xE0, 0xFC, 0xFD, 0xFD,
			0xFF, 0xFF, 0xFF, 0xBF, 0x81, 0xEF, 0xAF, 0x81, 0xFF, 0xE1, 0x81,
			0xC5, 0xC9, 0xFD, 0xF9, 0xF3, 0xE0, 0xF8, 0xFE, 0xFC, 0xE1, 0xF7,
			0xFF, 0xFF, 0xFB, 0xFC, 0x7C, 0x7E, 0x3F, 0x3E, 0x1F, 0x1F, 0x0F,
			0x0F, 0x07, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
			0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0x7E, 0xFA, 0xF9, 0xFC, 0xE2, 0xD9,
			0x9D, 0xDD, 0x43, 0x3F, 0x0F, 0x2F, 0x3F, 0x3F, 0xBF, 0x3E, 0xFE,
			0xFC, 0x7C, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0,
			0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0,
			0xF0, 0xF0, 0xF0, 0xF8, 0x78, 0x78, 0x7C, 0x7C, 0xFE, 0x1E, 0x7F,
			0xEF, 0xC7, 0x9F, 0x1B, 0xC3, 0x8F, 0xBF, 0xFF, 0xFF, 0xFE, 0xFC,
			0xF9, 0xFD, 0x7E, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x03, 0x0F, 0x3F, 0x7F, 0xFF, 0xFC, 0xFE, 0xF7, 0xF3, 0xB0,
			0x32, 0x33, 0x93, 0xCF, 0xDF, 0x7F, 0x7E, 0xFC, 0xF8, 0xF1, 0xE0,
			0xC0, 0xC0, 0x80, 0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x07, 0x07,
			0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
			0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x80, 0xC0, 0xE0,
			0xF0, 0xF0, 0xF8, 0xFC, 0x7F, 0x3F, 0x9F, 0xBF, 0x07, 0x04, 0xCE,
			0xD0, 0xF7, 0xF1, 0xFE, 0xFF, 0xFF, 0x7F, 0x1F, 0x07, 0x03, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF,
			0xDF, 0x9F, 0x8F, 0xAF, 0x27, 0x3F, 0x3F, 0xFF, 0xFE, 0xF8, 0xF0,
			0xC7, 0x01, 0x00, 0x1C, 0x7F, 0xFF, 0x01, 0x01, 0x03, 0x33, 0xF7,
			0xF6, 0xF6, 0xE6, 0xE6, 0xCC, 0x89, 0x02, 0x04, 0x04, 0x08, 0x00,
			0x10, 0x10, 0x00, 0x00, 0x20, 0x21, 0x21, 0x21, 0x21, 0x20, 0x20,
			0x00, 0x10, 0x10, 0x00, 0x08, 0x04, 0x04, 0x02, 0x85, 0xC6, 0xE6,
			0xE6, 0xF7, 0xF7, 0x73, 0x3B, 0x01, 0x00, 0x01, 0xFF, 0x3F, 0x08,
			0x00, 0x83, 0xC3, 0xF0, 0xFC, 0xFF, 0x7F, 0x1F, 0xBB, 0x38, 0x5A,
			0x11, 0xF7, 0xF1, 0xFD, 0xFF, 0xFF, 0xFF, 0x1F, 0x07, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F,
			0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0x9A, 0x9C, 0x8C, 0x85, 0xB7, 0x7F,
			0xFF, 0xFF, 0xF8, 0xC0, 0x07, 0x07, 0x01, 0xF8, 0xFE, 0x1F, 0x03,
			0xE6, 0xCC, 0x9C, 0x9C, 0x39, 0x38, 0x30, 0x62, 0x58, 0x20, 0x40,
			0x80, 0x00, 0x07, 0x07, 0x04, 0x04, 0x04, 0x07, 0x06, 0x03, 0x0F,
			0xFF, 0x30, 0x10, 0x10, 0xF8, 0xFF, 0x0F, 0x03, 0x06, 0x07, 0x04,
			0x04, 0x04, 0x06, 0x07, 0x00, 0x80, 0x40, 0x30, 0x6C, 0x33, 0x38,
			0x19, 0x9C, 0x9C, 0xCC, 0xE6, 0xE3, 0x01, 0x3F, 0xFE, 0xF8, 0x01,
			0x0F, 0x01, 0xC0, 0xFC, 0xFF, 0xFF, 0x4F, 0x92, 0x3E, 0x3E, 0x96,
			0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
			0x24, 0x2D, 0xAC, 0xA9, 0xA1, 0xFF, 0xFF, 0xFF, 0xE3, 0x00, 0x00,
			0x87, 0xF1, 0xF8, 0x7C, 0x1E, 0xC7, 0x8F, 0x38, 0x71, 0x63, 0xE7,
			0xCC, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
			0x00, 0x00, 0x00, 0xFB, 0x01, 0xFE, 0xFC, 0xF8, 0x00, 0x01, 0x01,
			0x00, 0xF8, 0xFC, 0x02, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x80, 0xE7, 0x63, 0x71,
			0x38, 0x1E, 0xC7, 0x87, 0x3E, 0x7C, 0xF8, 0xE3, 0x0F, 0x00, 0x00,
			0xFF, 0xFF, 0xFF, 0x6C, 0xEB, 0xEB, 0xEB, 0x09, 0x6E, 0xFF, 0xFF,
			0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0xA1, 0x3C, 0xBC,
			0x1D, 0xE1, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xF3, 0xF1, 0x79,
			0x38, 0x9C, 0x9E, 0x7E, 0xE0, 0x80, 0x0F, 0x7F, 0x1E, 0xC1, 0x10,
			0x02, 0x01, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x06, 0x06, 0x0A, 0x12,
			0x12, 0x26, 0x44, 0x08, 0x90, 0x30, 0x10, 0x90, 0x08, 0x04, 0x22,
			0x13, 0x03, 0x0B, 0x07, 0x03, 0x03, 0xFE, 0x00, 0x00, 0x00, 0x01,
			0x04, 0x31, 0x04, 0x7F, 0x1F, 0x80, 0xE0, 0x7F, 0x1E, 0xCE, 0x1C,
			0x3C, 0x78, 0xF1, 0xE0, 0x80, 0x01, 0x1F, 0xFF, 0xFF, 0xFD, 0x49,
			0x29, 0xA5, 0xA4, 0x2F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
			0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xF9, 0xF9,
			0xFC, 0xFF, 0xFE, 0x3F, 0x0F, 0x83, 0xC0, 0xE8, 0x66, 0x77, 0x73,
			0x33, 0x13, 0xF9, 0xF9, 0x05, 0xF0, 0xFC, 0x7F, 0x1F, 0x81, 0x00,
			0x20, 0x00, 0x08, 0x04, 0x04, 0x02, 0x02, 0x00, 0x01, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x04,
			0x00, 0x08, 0x10, 0x20, 0x41, 0x8F, 0x3F, 0xFC, 0xF8, 0x00, 0xFC,
			0xF9, 0x19, 0x19, 0x33, 0x73, 0x76, 0x74, 0xE0, 0xC1, 0x03, 0x0F,
			0x7E, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
			0xFF, 0xFF, 0xFE, 0xF8, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0,
			0xF8, 0xFE, 0xFF, 0xE7, 0x4F, 0x0F, 0x8F, 0x03, 0x31, 0x03, 0x63,
			0xF7, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x8E, 0x87, 0xC3, 0xD1, 0xD8,
			0xDC, 0xCC, 0xCE, 0xCE, 0xCE, 0xCE, 0x4E, 0x1E, 0x1E, 0x1E, 0x1E,
			0x1E, 0x1C, 0x1C, 0x19, 0x1A, 0x14, 0x14, 0x08, 0x08, 0x18, 0x18,
			0x38, 0x38, 0x39, 0x3D, 0x3C, 0x1E, 0x1E, 0x1E, 0x1F, 0x0F, 0x4F,
			0xCF, 0xCF, 0xCF, 0xCF, 0xCE, 0xCE, 0xCC, 0xC8, 0xD1, 0xC3, 0x87,
			0x0F, 0x1F, 0x3F, 0xFF, 0xEF, 0xC1, 0x81, 0x01, 0x01, 0x01, 0x00,
			0x00, 0x00, 0x03, 0x8F, 0xDF, 0xFC, 0xF8, 0xE0, 0x80, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
			0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xF9, 0xF1, 0xC0,
			0x88, 0x04, 0x00, 0x00, 0x80, 0xC1, 0xC0, 0xE0, 0x71, 0x3F, 0x3F,
			0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x43, 0xC3, 0x83, 0x03,
			0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x83,
			0xC3, 0x63, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x1F, 0x1F, 0x3F,
			0x39, 0x70, 0xE2, 0xF9, 0xC8, 0xC0, 0xC6, 0xD4, 0x90, 0xF9, 0xFC,
			0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0x80,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0xF0, 0x78, 0x38, 0x0C, 0x0C,
			0x1E, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0x7C,
			0x7C, 0x38, 0x00, 0x0E, 0x3A, 0x32, 0x82, 0x8E, 0xFF, 0xFF, 0xFF,
			0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0x87, 0x8B, 0xCB, 0x03, 0x00, 0xD0,
			0xD2, 0x92, 0xDE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F,
			0x02, 0x06, 0x0C, 0x9C, 0x18, 0x30, 0x70, 0x60, 0xC0, 0x80, 0x80,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x80, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0,
			0xF0, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
			0xF0, 0x70, 0x70, 0x70, 0x70, 0x70, 0x60, 0x60, 0xE0, 0xE0, 0xC0,
			0xC0, 0xC0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00,
			};
	
	public void print_image_test()
	{
		printer.esc.wakeUp();
		printer.esc.text.init();
		Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bird120);
		printer.esc.image.drawOut(0,0, bitmap);
		printer.esc.text.drawOut(0,30,"继续绘制文字\r\n");
		bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bird);
		printer.esc.image.printOut(0, bitmap, 0);
		bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.gongzhang250);
		printer.esc.image.printOutFast(0, bitmap, 0, 50);
		printer.esc.feedLines(3);
	}
	
	/*
	 * 以下排版是按3英寸打印机排版，请选用ULT113x系列，JLP351系列
	 */
	private boolean printESC() {
		SimpleDateFormat   formatter;
		ESC.LINE_POINT[] lines = new ESC.LINE_POINT[1];
		lines[0] = new ESC.LINE_POINT(0, 575);
		
		if (!printer.wakeUp())
			return false;
		if(printer.getModel() == PRINTER_MODEL.VMP02_P) {
			printer.esc.image.printOutFast(0, this.getResources(),R.drawable.gongzhang250);
			printer.esc.text.printOut(ALIGN.CENTER, ESC.FONT_HEIGHT.x24, true, ESC.TEXT_ENLARGE.HEIGHT_DOUBLE, "卫生行政执法文书");
		}
		else {
//			printer.esc.image.printOut(0,this.getResources(),R.drawable.gongzhang,0);	
			printer.esc.image.drawOut(32, 0, 106, 106, ESC.IMAGE_ENLARGE.NORMAL,
					logo_data);
			printer.esc.text.printOut(150, 29, ESC.FONT_HEIGHT.x24, true,
					ESC.TEXT_ENLARGE.HEIGHT_WIDTH_DOUBLE, "卫生行政执法文书");
		}
		for (int i = 0; i < 4; i++) {
			printer.esc.graphic.linedrawOut(lines);
		}
		printer.esc.feedDots(4);
		printer.esc.text.printOut(ALIGN.CENTER, ESC.FONT_HEIGHT.x24, true,
				ESC.TEXT_ENLARGE.NORMAL, "现场检测笔录");
		if(printer.getModel() == PRINTER_MODEL.VMP02) {
			printer.esc.barcode.code128_auto_printOut(ALIGN.CENTER,
				ESC.BAR_UNIT.x2, 56, ESC.BAR_TEXT_POS.BOTTOM,
				ESC.BAR_TEXT_SIZE.ASCII_8x16, "A02161645760");
		} else {
			printer.esc.barcode.code128_auto_printOut(ALIGN.CENTER,
					ESC.BAR_UNIT.x3, 56, ESC.BAR_TEXT_POS.NONE,
					ESC.BAR_TEXT_SIZE.ASCII_8x16, "A02161645760");
		
		}


		printer.esc.text.printOut("被检查人：上海济强电子科技有限公司");
		printer.esc.text.printOut("联系电话：13371967607" + "   邮政编码：201206");
		printer.esc.text.printOut("法定代表人(或责任人)：张三" + "   职务：总经理");
		printer.esc.text.printOut("检查机关：浦东1队");
		formatter   =   new   SimpleDateFormat("yyyy年MM月dd日HH时");  
		printer.esc.text.printOut("检查时间：" + formatter.format(System.currentTimeMillis()));
		printer.esc.text.printOut("检查地点：浦东金藏路258号2号楼2层\n");
		printer.esc.text.drawOut("检查人员示证检查，检查记录：\n");
		printer.esc.text.printOut("    卫生监督员" + "李四" + "和" + "王二" + "在" + "赵大"
				+ "的陪同下,对" + "上海济强电子科技有限公司" + "进行了检查，经检查发现：");
		printer.esc.text.printOut("1.门外有垃圾。\n2.门口有小广告。\n3.厕所未及时清洁。\r\n");
		
		if(printer.getModel() != PRINTER_MODEL.VMP02)
		{
			//unit        version    ecc
			//BAR_UNIT.x3, 0 ,       2    可打印280个汉字
			printer.esc.barcode.barcode2D_QRCode(0,0,BAR_UNIT.x3,0,2,"二维条码一二器把寄是1" +
					"三四武六器把九十寄是2" +
					"一二三四武六器把九03" 
					+
					"一二三四武六器把九04" +
					"一二三四武六器把九05" +
					"一二三四武六器把九06" +
					"一二三四武六器把九07" +
					"一二三四武六器把九08" +
					"一二三四武六器把九09" +
					"一二三四武六器把九10"+
					"一二三四武六器把九11" +
					"一二三四武六器把九12" +
					"一二三四武六器把九13" +
					"一二三四武六器把九14" +
					"一二三四武六器把九15" +
					"一二三四武六器把九16" +
					"一二三四武六器把九17" +
					"一二三四武六器把九18" +
					"一二三四武六器把九19" +
					
					"一二三四武六器把九20" +
					"一二三四武六器把九21" +
					"一二三四武六器把九22" +
					"一二三四武六器把九23" +
					"一二三四武六器把九24" +
					
					"一二三四武六器把九25" +
					"一二三四武六器把九26" +
					"一二三四武六器把九27" +
					"一二三四武六器把九十");
//);
			printer.esc.feedEnter();
		}
	
	
	
		printer.esc.feedDots(200);
		printer.esc.text.setBold(true);	
		printer.esc.text.printOut("被检查人阅后签名：\n");
		printer.esc.text.drawOut(0, 16, "日期    年  月  日");
		printer.esc.text.drawOut(280, 32, "卫生行政机关盖章");
		 formatter   =   new   SimpleDateFormat("yyyy年MM月dd日");
		printer.esc.text.drawOut(280, 0, formatter.format(System.currentTimeMillis()));
		printer.esc.feedEnter();
		printer.esc.text.printOut("卫生监督员签名：\n");
		printer.esc.text.printOut("日期    年  月  日");
		for (int i = 0; i < 4; i++) {
			printer.esc.graphic.linedrawOut(lines);
		}
		printer.esc.feedDots(4);
		printer.esc.text.printOut(ALIGN.RIGHT, ESC.FONT_HEIGHT.x16, false,
				ESC.TEXT_ENLARGE.NORMAL, "中华人民共和国卫生部制定");

		
		
      //支付宝sample	
//		printer.esc.text.printOut("批次号：200122");
//		printer.esc.barcode.CODE128_auto("200122-1");
//		printer.esc.text.printOut("批次类型：定时达");
//		printer.esc.text.printOut("包裹数量：2");
//		printer.esc.text.printOut("包裹号：200122-1");
//		printer.esc.text.printOut("订单数量：3");
//		
//		for (int i = 0; i < 4; i++) {
//		printer.esc.graphic.linedrawOut(lines);
//		}
//		
//		printer.esc.text.printOut("              XX");
//		printer.esc.text.printOut("           支付宝会员店");
//		printer.esc.barcode.CODE128_auto("10000001");
//		printer.esc.text.printOut("订单号：10000001");
//		printer.esc.text.printOut("订单类型：定时达");
//		printer.esc.text.printOut("预计送达时间：");
//		printer.esc.text.printOut("客户姓名：");
//		printer.esc.text.printOut("联系电话：");
//		printer.esc.text.printOut("收货地址：");
//		printer.esc.text.printOut("商品名称  服务  单价  数量  金额");
//
//		for (int i = 0; i < 4; i++) {
//			printer.esc.graphic.linedrawOut(lines);
//			}
//		printer.esc.feedDots(80);
//		for (int i = 0; i < 4; i++) {
//			printer.esc.graphic.linedrawOut(lines);
//			}
//
//		printer.esc.text.printOut("                   合计：100");
//		printer.esc.text.printOut("                   优惠金额：20");
//		printer.esc.text.printOut("                   订单金额：80");
//		printer.esc.text.printOut("缺货商品信息");
//		printer.esc.text.printOut("商品名称  服务  单价  数量  金额");
//		for (int i = 0; i < 4; i++) {
//			printer.esc.graphic.linedrawOut(lines);
//			}
//		printer.esc.text.printOut("订单号：10000001");
//		printer.esc.text.printOut("客户签字：啊啊：");
//		printer.esc.text.printOut("           xx");
//		printer.esc.text.printOut("       支付宝会员店");
//		
//		printer.esc.feedEnter();
	

		return true;
	}
	
	private boolean getPrinterState()
	{	
		if (!printer.getPrinterState(3000))
		{
			Toast.makeText(this, "获取打印机状态失败", Toast.LENGTH_SHORT).show();
			return false;
		}
		
		if (printer.isCoverOpen)
		{
			Toast.makeText(this, "打印机纸仓盖未关闭", Toast.LENGTH_SHORT).show();
			return false;
		}
		else if (printer.isNoPaper)
		{
			Toast.makeText(this, "打印机缺纸", Toast.LENGTH_SHORT).show();			
			return false;
		}
		return true;
	}
	
	public void EnforcementPrintButton_click(View view)
	{
		if (printer == null)
		{
			Log.e("JQ", "printer null");
			return;
		}
		buttonPrint.setVisibility(Button.INVISIBLE);
		
	/*	if (!getPrinterState())
		{
			buttonPrint.setVisibility(Button.VISIBLE);;
			return ;
		}*/
		
	//	print_image_test();
		printESC();//第一联	
	//	printer.feedRightMark();
	//	print();//第二联
	//	printer.feedLeftMark();
		int i=0;
		try {Thread.sleep(5000);} catch (InterruptedException e) {}
		for (i = 0; i < 10; i++) {
			if (!printer.getPrinterState(3000)) { //超时时间过短也会造成获取状态失败，此超时时间和打印机内容多少有关。
				//Toast.makeText(this, "获取打印机状态失败", Toast.LENGTH_SHORT).show();
				try {Thread.sleep(1000);} catch (InterruptedException e) {}
				continue;
			}
			if (printer.isCoverOpen) {
				Toast.makeText(this, "打印机纸仓盖未关闭", Toast.LENGTH_SHORT).show();
				return;
			} else if (printer.isNoPaper) {
				Toast.makeText(this, "打印机缺纸", Toast.LENGTH_SHORT).show();
				return;
			}
			if (!printer.isPrinting) //表示打印结束
			{
				Toast.makeText(this, "打印结束", Toast.LENGTH_SHORT).show();
				break; 
			}
			else //否则等待500ms,并继续获取状态
			{
				try {Thread.sleep(500);} catch (InterruptedException e) {}
			}
		}
		if (i == 10)
		{
			Toast.makeText(this, "打印出错", Toast.LENGTH_SHORT).show();
		}
		
		buttonPrint.setVisibility(Button.VISIBLE);
	}
	
	@Override
	public void finish() 
	{
		super.finish();			
	}
	
	public void EnforcementSetting_click(View view)
	{
		Intent myIntent = new Intent(ebMainActivity.this, ebSettingActivity.class);
    	startActivity(myIntent);		
	}    

}
